<?php

namespace App\Miya\Models;

use App\Miya\Traits\Scope\OrderByIdTrait;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Str;
use phpDocumentor\Reflection\Types\False_;

class Area extends Model
{
    use OrderByIdTrait;

    protected $guarded = [];

    public function province()
    {
        return $this->belongsTo(ChinaArea::class, 'province_id', 'code');
    }

    public function city()
    {
        return $this->belongsTo(ChinaArea::class, 'city_id', 'code');
    }

    public function district()
    {
        return $this->belongsTo(ChinaArea::class, 'district_id', 'code');
    }

    public function derivatives()
    {
        return $this->hasMany(DerivativeKeyword::class);
    }

    public function getFullNameAttribute()
    {
        $areaIds = [$this->province_id, $this->city_id, $this->district_id];
        return ChinaArea::whereIn('code', $areaIds)->pluck('name')->join('-');
    }

    public function modules()
    {
        return new Module();
    }
}
